<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="keywords" placeholder="请关键词" autocomplete="off" class="layui-input"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="search">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('添加新闻','./news-add.jsp',550,700)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table" id="resultTable" lay-filter="resultTable">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- templet -->
    <script type="text/html" id="toolbarDemo">
        <div class = "layui-btn-container" > 
            <button class = "layui-btn layui-btn-sm" lay-event = "getCheckData" > 获取选中行数据 </button>
            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button > 
            <button class = "layui-btn layui-btn-sm" lay-event = "isAll" > 验证是否全选</button>
        </div >
    </script>
    <!-- templet -->
        <script type="text/html" id="toolInTable">
            <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>
    <script type="text/html" id="switchTpl">
        <!-- 这里的checked的状态只是演示 -->
        <input type = "checkbox" name = "sex" value = "{{d.id}}" lay-skin = "switch"lay-text = "女|男" lay-filter = "sexDemo" {{ d.id == 10003 ? 'checked': ''}} >
    </script>
    <!-- loading all needed component -->
    <script>
        /**
         * laydate: date component
         */
        layui.use('laydate',
        function() {
            // binding logic
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });
            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });

        });
    </script>

    <script>
        layui.use(['table','form'], function(){
            var table = layui.table;
            var form = layui.form ;

            table.render({
                elem: '#resultTable'  // table id
                ,url:'${pageContext.request.contextPath}/adminx/news?action=findByPage'
                ,title: '新闻数据表'
                ,cols: [[
                    {field:'newsId', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                    ,{field:'title', title:'新闻标题', width:250, edit: 'text'}
                    ,{field:'categoryName', title:'新闻类别', width:150, edit: 'text'}
                    ,{field:'publishTime', title:'发布时间', width:200, sort: true}
                    ,{field:'content', title:'发布内容', width:500 }
                    ,{field:'publishStatus', title:'发布状态', width:180, edit: 'text', sort: true}
                    ,{title:"操作", fixed:'right', width:250, align:'center', toolbar:'#toolInTable'}
                ]]
                ,toolbar: true
                ,totalRow: true
                ,page: true
                ,response: {
                    statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
                }
                ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                }
            });

            form.on('submit(search)', function(obj) {
                console.log("formdata: " + obj.field.start + ", " +obj.field.end +", " +obj.field.keywords) ;
                table.reload('resultTable', {
                    where: {
                        start: obj.field.start,
                        end: obj.field.end,
                        keywords:obj.field.keywords
                    },
                    page: {
                        curr : 1
                    }
                }) ;
                return false;
            })

        });



    </script>


    <script>
        layui.use(['table','layer', 'jquery'],
        function() {
            var table = layui.table;
            var layer = layui.layer ;
            var $ = layui.jquery ;

            //监听单元格编辑
          /*  table.on('edit(test)',
            function(obj) {
                var value = obj.value //得到修改后的值
                ,
                data = obj.data //得到所在行所有键值
                ,
                field = obj.field; //得到字段
                layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
            });*/

            //头工具栏事件
            table.on('tool(resultTable)',
            function(obj) {
                var data = obj.data;
                json = JSON.stringify(data) ;
                var event = obj.event ;
                if (event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '修改新闻',
                        content: ['news-add.jsp',"no"],
                        maxmin: true,
                        area: ['550px', '750px'],
                        success:function(layero, index) {
                            var body = layer.getChildFrame('body', index) ;
                            body.find('input[name=title]').val(data.title) ;
                        }

                    }) ;


                }


            });
        });</script>
    <script>var _hmt = _hmt || []; (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();</script>

</html>